package quizman;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dsrg.servlet.app.frontController.Servlet;

import quizman.domain.Quiz;
public class ViewQuizPageController extends Servlet {

	private static final long serialVersionUID = 1L;

	protected void processRequest(
			HttpServletRequest request,
			HttpServletResponse response)
	throws ServletException, java.io.IOException //
	{
		String qname = request.getParameter("quizName");
		try {
			Quiz q = ViewQuizTS.execute(qname);
			if(q==null)
				throw new RuntimeException("Quiz not in database");
			request.setAttribute("quiz", q);
			getDispatcher("ViewQuiz.jsp", request).forward(request, response);
		} catch (Exception e) {
			request.setAttribute("error", e);
			request.setAttribute("message", "Error processing in servlet "+getClass().getSimpleName()+",\n"+
					"while searching for quiz: "+qname+".\n");
			getDispatcher("Error.jsp", request).forward(request, response);
		}
	}
}
